# -*- coding: utf-8 -*-



"""
工厂方法模式

模式特点：定义一个用于创建对象的接口，让子类决定实例化哪一个类。这使得一个类的实例化延迟到其子类。

程序实例：基类雷锋类，派生出学生类和志愿者类，由这两种子类完成“学雷锋”工作。子类的创建由雷锋工厂的对应的子类完成。

代码特点：无
"""


class LeiFeng(object):

    def sweep(self):
        print "Lei Feng sweep"


class Student(LeiFeng):

    def sweep(self):
        print "Student Sweep"


class Volunteer(LeiFeng):

    def sweep(self):
        print "Volunteer Sweep"


class LeiFengFactory(LeiFeng):

    def create_leifeng(self):
        temp = LeiFeng()
        return temp


class StudentFactory(LeiFengFactory):

    def create_leifeng(self):
        return Student()


class VolunteerFactory(LeiFengFactory):

    def create_leifeng(self):
        return Volunteer()

if __name__ == "__main__":

    sf = StudentFactory()
    s = sf.create_leifeng()
    s.sweep()

    sdf = VolunteerFactory()
    sd = sdf.create_leifeng()
    sd.sweep()





